package com.hongning.railway.ui.main.fragments.college.exam;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.data.AppRepository;
import com.hongning.railway.databinding.FragmentExamresultBinding;
import com.hongning.railway.entity.reqbean.ReqAnswerCheck;
import com.hongning.railway.entity.resbean.BaseResExam;
import com.hongning.railway.entity.resbean.ResAnswerCheck;
import com.hongning.railway.entity.resbean.ResAnswerSubmitBean;
import com.hongning.railway.ui.main.fragments.college.exam.itemviewmodel.AnswerCheckItemViewModel;
import com.hongning.railway.ui.main.fragments.college.exam.itemviewmodel.ExamItemViewModel;
import com.hongning.railway.util.Apputils;

import java.text.NumberFormat;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 * Author: zhangjing
 * DATA:2019-08-20 15:40
 * DESC:
 * email:zhangjingworkmol@163.com
 */
public class CheckAnswerFragmentViewModel extends BaseViewModel<AppRepository> {
    public ItemBinding<AnswerCheckItemViewModel> item = ItemBinding.of(BR.viewModel, R.layout.item_answer_check);
    public ObservableList<AnswerCheckItemViewModel> viewlist = new ObservableArrayList<>();
    public ObservableField<String> currentpos = new ObservableField<>();

    public CheckAnswerFragmentViewModel(@NonNull Application application, AppRepository model) {
        super(application, model);
    }

    public void loadAnswerResult(String examid,String resultId){
        ReqAnswerCheck reqAnswerCheck = new ReqAnswerCheck();
        reqAnswerCheck.setExamId(examid);
        reqAnswerCheck.setResultId(resultId);
        reqAnswerCheck.setStaffId(Apputils.getStaffid());
        model.answerCheck(reqAnswerCheck)
                .compose(RxUtils.bindToLifecycle(getLifecycleProvider()))
                .compose(RxUtils.schedulersTransformer())
                .subscribe(new ApiDisposableObserver<BaseResExam<ResAnswerCheck>>() {
                    @Override
                    public void onResult(BaseResExam<ResAnswerCheck> resAnswerCheckBaseResExam) {
                        for (ResAnswerCheck data :resAnswerCheckBaseResExam.getDataList()) {
                            viewlist.add(new AnswerCheckItemViewModel(CheckAnswerFragmentViewModel.this,data));
                        }
                    }
                });
    }
}
